﻿using JobSearcherAPI.Models;
using JobSearcherAPI.Search;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JobSearcherAPI
{
    public class JobSearch
    {
        public JobSearch(string apiKeysFile) 
        {
            var file = System.IO.File.OpenRead(apiKeysFile);
            GetKeys(apiKeysFile);
        }

        private void GetKeys(string apiKeysFile)
        {
            using (var sr = new StreamReader(apiKeysFile))
            {
                JobSite.AddKeys(sr.ReadToEnd());
            }
        }

        public List<string> SearchEngineList()
        {
            return JobSite.SearchEngineList;
        }

        public async Task<SearchResult> Search(string site, SearchArguments arguments)
        {
            JobSite searcher = JobSite.SearcherByName(site);
            return await searcher.GetSearchResults(arguments);
        }
    }
}
